﻿using System;
using System.Collections.Generic;

namespace JQuery.WebKit
{

    public delegate void JValidationMessageAdded(object sender, JValidationMessageArgs e);

    public class JValidationMessageArgs : EventArgs
    {
        public JValidationMessage Message { get; set; }
        public JValidationMessageArgs(JValidationMessage message)
        {
            Message = message;
        }
        public  JValidationMessageArgs()
        {
        }
    }

    public class JValidationMessageCollection : List<JValidationMessage>
    {
        public event JValidationMessageAdded MessageAdded;

        public virtual void OnMessageAdded(JValidationMessage message)
        {
            if (MessageAdded != null)
            {
                MessageAdded(this, new JValidationMessageArgs(message));
            }
        }

        public void Add(string newMessage, JValidationType messageType)
        {
            var msg = new JValidationMessage(newMessage, messageType);
            base.Add(msg);
            OnMessageAdded(msg);
        }
    }
}
